 {extend name="v1/layout/base"}
 {block name="content"}
 <div class="layuimini-main">

   <fieldset class="table-search-fieldset xk-search-status" id="xk-search-status">
     <legend>搜索信息</legend>
     <div style="margin: 10px 10px 10px 10px">
       <div class="layui-row layui-col-space15">
         <div class="layui-col-md6 xz_width">
           <form class="layui-form">
             <div class="layui-card-body layui-form layui-form-pane">
               <div class="layui-row layui-col-space10 layui-form-item">
                 <div class="layui-col-lg12">
                   <label class="layui-form-label">搜索关键词</label>
                   <div class="layui-input-block">
                     <input type="text" name="keywords" placeholder="请输入搜索关键词" id="keywords" class="layui-input">
                   </div>
                 </div>
               </div>
               <div class="layui-row">
                 <div class="layui-col-xs4">&nbsp;</div>
                 <div class="layui-col-xs4">
                   <button type="reset" class="layui-btn layui-btn-primary  xk-refresh"><i class="fa fa-refresh"></i>&nbsp;重置</button>
                   <button type="button" class="layui-btn layui-btn-normal xk-dosearch">搜索<i class="layui-icon"></i></button>
                   <button type="button" class="layui-btn layui-btn-primary close-search"><i class="layui-icon">&#x1007;</i>关闭</button>
                 </div>
                 <div class="layui-col-xs4">&nbsp;</div>
               </div>
             </div>
           </form>
         </div>
       </div>
     </div>
   </fieldset>


   <script type="text/html" id="toolbar">
     <div class="layui-btn-container">
       <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
     </div>
   </script>

   <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

   <script type="text/html" id="currentTableBar">
     <button class="layui-btn layui-btn-radius layui-btn-warm layui-btn-sm" lay-event="show" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/User/userLevelEdit"><i class="layui-icon">&#xe642;</i>编辑</button>
   </script>
   <!-- 图片 如果存在的话 -->
   <script type="text/html" id="picurlshow">
     <img src="{{d.picurl?d.picurl:'__COMMON__images/no_pic.png'}}" style="width:100px; height:100%" />
   </script>
 </div>
 {/block}
 {block name="myScript"}
 <style media="screen">
   .layui-table-cell {
     height: 100px;
     line-height: 100px;
   }
 </style>
 <script>
   layui.use(['form', 'table', 'laydate'], function() {
     var $ = layui.jquery,
       form = layui.form,
       laydate = layui.laydate,
       table = layui.table;
     laydate.render({
       elem: '#search_time',
       range: '~',
       theme: '#1E9FFF',
       format: 'yyyy-MM-dd'
     });
     table.render({
       elem: '#currentTableId',
       url: '/{:config("manage.manage_name")}/{:config("manage.version")}/User/userLevel',
       toolbar: '#toolbar',
       defaultToolbar: ['filter'],
       cols: [
         [{
             field: 'user_level_id',
             width: '100',
             title: 'ID',
             sort: true
           },
           {
             field: 'picurl',
             width: '150',
             title: '等级图标',
             templet: "#picurlshow"
           },
           {
             field: 'level_name',
             width: '100',
             title: '等级名称',
             edit: 'text',
           },
           {
             field: 'level',
             width: '200',
             title: '等级',
             edit: 'text',
           },
           {
             field: 'buy_num',
             width: '200',
             title: '升级-购买单数',
             edit: 'text',
           },
           {
             field: 'team_achievement_price',
             width: '200',
             title: '升级-伞下团队业绩',
             edit: 'text',
           },
           {
             field: 'agent_bili',
             width: '200',
             title: '代理佣金比例',
             edit: 'text',
           },
           {
             field: 'avg_bili',
             width: '200',
             title: '平级奖比例',
             edit: 'text',
           },
           {
             field: 'child_num',
             width: '200',
             title: '升级-下等级数量',
             edit: 'text',
           },
           {
             field: 'create_time',
             title: '创建时间',
             minWidth: '500'
           },
           {
             title: '操作',
             toolbar: '#currentTableBar',
             minWidth: '100',
             fixed: 'right',
             align: "center"
           }
         ]
       ],
       limits: [100, 150, 200, 250, 500, 1000],
       limit: 100,
       id: 'table_ids',
       page: true,
       skin: 'line'
     });

     // 列表工具栏目
     table.on('tool(currentTableFilter)', function(obj) {
       var data = obj.data,
         event = obj.event,
         keywords = $("#keywords").val(),
         url = $(this).attr('data-url');
       url = url + '/user_level_id/' + data.user_level_id;
       switch (event) {
         case 'show':
           var index = layer.open({
             title: '会员等级' + data.level_name + '编辑',
             type: 2,
             shade: 0.2,
             maxmin: true,
             shadeClose: true,
             area: ['100%', '100%'],
             content: url,
             cancel: function() {
               table.reload('table_ids', {
                 where: {
                   keywords: keywords
                 }
               });
             }
           });
           break;
       }
     })

     // 顶部操作工具
     table.on('toolbar(currentTableFilter)', function(obj) {
       var url = $(this).attr('data-url'),
         keywords = $("#keywords").val(),
         id_arr = getCheckValue();
       switch (obj.event) {
         case 'reseve':
           table.reload('table_ids');
           break;
         case 'search':
           $("#xk-search-status").removeClass('xk-search-status');
           break;
       }
     })
     // 监听单元格编辑事件
     table.on('edit(currentTableFilter)', function(obj) {
       var value = obj.value
       by_key = obj.data.user_level_id,
         key = obj.field;
       if (value == '') {
         table.reload('table_ids', {}, 'data');
         return false;
       }
       var url = "{:url('/'.config('manage.manage_name').'/'.config('manage.version').'/User/userLevelChanageValue')}";
       https(url, {
         by_key: by_key,
         key: key,
         value: value
       }, 'post', true, '正在修改').then(res => {
         if (res.result_code == 200) {
           table.reload('table_ids', {}, 'data');
         }
       })
     });

   });
 </script>
 {/block}
